<template>
   <div class="AccountPassword">
     <div class="AccountPassword-newPassword">
       <span>输入新密码：</span>
       <el-input placeholder="请输入密码" v-model.trim="user.newPassword" show-password></el-input>
     </div>
     <div class="AccountPassword-repeat">
       <span>确认新密码：</span>
       <el-input placeholder="确认新密码" v-model.trim="user.PasswordConfirm" show-password></el-input>
     </div>
     <div class="AccountPassword-PasswordConfirm">
       <el-button type="danger" @click="TchangePassword">确认</el-button>
     </div>
   </div>
</template>

<script>
import {Message} from "element-ui";
import {changePassword} from "@/api/user";

export default {
  name: "AccountPassword",
  data(){
    return{
      user:{
         newPassword:"",
        PasswordConfirm:""
      }
    }
  },
  methods:{
    TchangePassword(){
        if(this.user.newPassword==""||this.user.PasswordConfirm==""){
          Message.error("输入框不能为空")
        }else {
          if(this.user.PasswordConfirm!==this.user.newPassword){
            Message.error("输入有误，请确认两次输入相同")
          }else {
            changePassword(this.user.newPassword).then(res=>{
              if (res){
                setTimeout(()=>{
                   window.history.go(-1);
                },2000)
              }
            });
          }
        }
    }
  }
}
</script>

<style >
.AccountPassword{
  height: 200px;
  text-align: center !important;
  margin-top: 30px;

}
.el-input--suffix{
  width: 300px;
}
.AccountPassword>div{
  margin-bottom: 20px;
}


</style>